package com.wandian.setting.mvvm.editbrief;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;

import androidx.databinding.DataBindingUtil;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.utils.StatusBarUtils;
import com.mylib.libcore.utils.ToastUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.setting.R;
import com.wandian.setting.databinding.SetActivityEditBriefBinding;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 个人介绍
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_SETTING_EDIT_BRIEF)
public class EditBriefActivity extends  BaseMVVMActivity<EditBriefViewModel>  {
    private SetActivityEditBriefBinding dataBinding;
    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.set_activity_edit_brief);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initViewData();
        initClink();
    }
    private void initViewData(){
        //设置状态颜色和字体黑色
        StatusBarUtils.with(this,false)
                .setIsActionBar(false)
                .clearActionBarShadow()
                .setDrawable(getResources().getDrawable(com.mylib.libcore.R.drawable.sys_color))
                .init();
        dataBinding.bindSysToolBar.toolBarTvTitle.setText("个人介绍");
        dataBinding.bindSysToolBar.toolBarTitleRight.setVisibility(View.VISIBLE);
        dataBinding.bindSysToolBar.toolBarTitleRight.setText("保存");

    }
    private void initClink(){

        dataBinding.etDesc.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if(!UIUtils.isEmpty(s)){
                    dataBinding.tvNumber.setText(s.toString().trim().length()+"");
                }else {
                    dataBinding.tvNumber.setText("0");
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        dataBinding.bindSysToolBar.toolBarIvBack.setOnClickListener(v -> {
            finishhideSoftBoard();
            finish();
        });
        dataBinding.bindSysToolBar.toolBarTitleRight.setOnClickListener(v -> {
            finishhideSoftBoard();
            if(UIUtils.isEmpty(dataBinding.etDesc.getText()) || dataBinding.etDesc.getText().toString().trim().length()<1){
                ToastUtil.show("请写点什么在保存吧~");
                return;
            }
            mViewModel.upDescription(dataBinding.etDesc.getText().toString().trim());

        });
    }

    @Override
    protected void onDestroy() {
        finishhideSoftBoard();
        super.onDestroy();
    }
}
